package com.example.appbarlayoutdemo.adapter;

import android.graphics.Paint;
import android.widget.ImageView;
import android.widget.TextView;

import androidx.annotation.Nullable;

import com.bumptech.glide.Glide;
import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.example.appbarlayoutdemo.R;
import com.example.appbarlayoutdemo.bean.DataListBean;
import com.example.appbarlayoutdemo.bean.GoodsTagListBean;

import java.util.List;

/**
 * @author: njb
 * @date: 2020/3/31 0031 22:18
 * @desc:
 */
public class ShopClassifyAdapter extends BaseQuickAdapter<DataListBean, BaseViewHolder> {
    private ImageView imageView;
    private TextView tvMarkOne, tvMarkTwo, tvMarkThree,tvPrice,tvDiscountPrice;
    private List<GoodsTagListBean> tagBean;
    private TextView tvEnName,tvName;
    public ShopClassifyAdapter(@Nullable List<DataListBean> data) {
        super(R.layout.item_shop_sort,data);
    }

    @Override
    protected void convert(BaseViewHolder helper, DataListBean item) {
        imageView = helper.getView(R.id.iv_shop);
        tvMarkOne = helper.getView(R.id.tv_flex_one);
        tvMarkTwo = helper.getView(R.id.tv_flex_two);
        tvMarkThree = helper.getView(R.id.tv_flex_three);
        tvPrice = helper.getView(R.id.tv_price);
        tvDiscountPrice = helper.getView(R.id.tv_discount_price);
        tvEnName = helper.getView(R.id.tv_en_name);
        tvName = helper.getView(R.id.tv_description);
        tagBean = item.getGoodsTagList();
        if (tagBean != null && tagBean.size() > 0) {
            for(int i=0;i<tagBean.size();i++){
                if(tagBean.size()==1){
                    tvMarkOne.setText(tagBean.get(0).getTagName());
                } else if(tagBean.size()==2){
                    tvMarkOne.setText(tagBean.get(0).getTagName());
                    tvMarkTwo.setText(tagBean.get(1).getTagName());
                } else if(tagBean.size()==3){
                    tvMarkOne.setText(tagBean.get(0).getTagName());
                    tvMarkTwo.setText(tagBean.get(1).getTagName());
                    tvMarkThree.setText(tagBean.get(2).getTagName());
                }else {
                    tvMarkOne.setText(tagBean.get(0).getTagName());
                    tvMarkTwo.setText(tagBean.get(1).getTagName());
                    tvMarkThree.setText(tagBean.get(2).getTagName());
                }
            }
        }
        //商品英文名称
        tvEnName.setText(item.getBrandNameEn());
        //商品名称
        tvName.setText(item.getGoodsName());
        if (item.getOfficialPrice() != null && !item.getOfficialPrice().equals("")) {
            //官方价格
            tvDiscountPrice.setText("￥" + item.getOfficialPrice());
            tvDiscountPrice.getPaint().setAntiAlias(true);//抗锯齿
            tvDiscountPrice.getPaint().setFlags(Paint.STRIKE_THRU_TEXT_FLAG | Paint.ANTI_ALIAS_FLAG); //中划线
        } else {
            helper.setText(R.id.tv_discount_price, "");
        }
        if (item.getSellingPrice() != null && !item.getSellingPrice().equals("")) {
            //商品售价
            tvPrice.setText("￥" + item.getSellingPrice());

        } else {
            helper.setText(R.id.tv_price, "" + item.getSellingPrice());
        }
        //商品折扣
        //helper.setText(R.id.tv_discount,item.getBrandNameCn());
        //商品图片
        Glide.with(mContext).load(item.getPictureUrl()).into(imageView);
    }
}
